package org.cocos2dx.fanpaiji.wxapi;
import android.os.Bundle;
import android.util.Log;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;

import org.cocos2dx.javascript.AppActivity;
import org.cocos2dx.lib.Cocos2dxActivity;


public class WXEntryActivity extends Cocos2dxActivity implements IWXAPIEventHandler {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		try {
			boolean result = AppActivity.wxapi.handleIntent(getIntent(), this);
			if(!result){
				this.finish();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void onReq(BaseReq baseReq) {
		//微信请求第三方应用回调

	}

	@Override
	public void onResp(BaseResp baseResp) {
		//第三方请求微信后微信返回信息回调

		int errorCode = baseResp.errCode;
		switch (errorCode) {
			case BaseResp.ErrCode.ERR_OK:
				//用户同意
				String code = "";
				String state = "";
				System.out.println("---------------分享成功="+baseResp.getType());
				if(baseResp.getType() == 2){
					AppActivity.app.onShared("已分享!");
					System.out.println("已分享!");
				}else{
					//用户同意
					code = ((SendAuth.Resp) baseResp).code;
					state = ((SendAuth.Resp) baseResp).state;
					AppActivity.app.onGetAuth(code, state);
				}
				break;
			case BaseResp.ErrCode.ERR_AUTH_DENIED:
				System.out.println("用户拒绝！");
				//用户拒绝
				break;
			case BaseResp.ErrCode.ERR_USER_CANCEL:
				System.out.println("用户取消！");
				//用户取消
				break;
			default:
				break;
		}
	}
}
